package com.ihmp.dao;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.ihmp.model.Thotels;
import com.ihmp.model.Troomtypes;

@Repository("hotelDAO")
public class HotelDAO {
	
	@Autowired
	private SessionFactory sessionFactory;
	
	public void add(Thotels hotel){
		sessionFactory.getCurrentSession().save(hotel);
	}
	
	public void update(Thotels hotel){
		sessionFactory.getCurrentSession().update(hotel);
	}
	
	public void delete(Integer id){
		Thotels hotel = get(id);
		sessionFactory.getCurrentSession().delete(hotel);
	}
	
	public Thotels get(Integer id){
		return (Thotels) sessionFactory.getCurrentSession().get(Thotels.class, id);
	}
	
	@SuppressWarnings("unchecked")
	public List<Thotels> list(){
		return (List<Thotels>) sessionFactory.getCurrentSession().createQuery("from Thotels h order by h.rank").list();
	}
	

	
	public LinkedHashMap<Integer, String> map(){
		ArrayList<Thotels> hotelList = (ArrayList<Thotels>) list();
		LinkedHashMap<Integer, String> hotelMap = new LinkedHashMap<Integer,String>();
		for(Thotels hotel : hotelList){
			hotelMap.put(hotel.getHotelId(), hotel.getHotelName());
		}
		return hotelMap;
	}
	
	
}
